<template>
  <div>
    <div class="cate_side">
      <van-sidebar v-model="activeKey" @change="change">
        <van-sidebar-item
          :title="item.name"
          v-for="item in categoryList"
          :key="item.id"
        />
      </van-sidebar>
      <div class="cate_content">
        <img :src="currentCategory.banner_url" alt="" />
        <div class="title">
          {{ currentCategory.front_name }}
        </div>

        <van-panel :title="currentCategory.name">
          <div>
            <van-grid column-num="3">
                <van-grid-item
                v-for="item in  currentCategory.subCategoryList" :key="item.id"
                 :icon="item.banner_url" :text="item.name" 
                />
         
                </van-grid>
          </div>
        </van-panel>
      </div>
    </div>
  </div>
</template>

<script>
import { GetCatalog ,GetCurrent} from "@/api";
export default {
  async created() {
    const {
      data: {
        data: { categoryList, currentCategory },
      },
    } = await GetCatalog();
    this.currentCategory = currentCategory;
    this.categoryList = categoryList;
  },
  data() {
    return {
      activeKey: 0,
      categoryList: [],
      currentCategory: [],
    };
  },
  methods: {
    async change(index) {
    //   console.log(index);
      this.activeKey = index;
    //  const {data:{data:currentCategory}} =  await GetCurrent(this.categoryList[index].id);
     const result =  await GetCurrent(this.categoryList[index].id);
     console.log(result.data.data.currentCategory);
     this.currentCategory=result.data.data.currentCategory;
    },
  },
};
</script>

<style>
.cate_side {
  display: flex;
}
.cate_side .cate_content {
  position: relative;
  width: calc(100% - 80px);
  flex: 1;
}
.cate_side .van-sidebar {
  height: 100vh;
  background-color: #f7f8fa;
}
.cate_content img {
  width: 100%;
  border-radius: 20px;
}
.cate_side .cate_content .title {
  position: absolute;
  left: 50%;
  top: 8%;
  transform: translate(-50%, -50%);
  text-shadow: 0.05333rem 0 0.16rem #8b0000;
  color: white;
  z-index: 999;
}
.van-cell__title{
    text-align: center;
    font-size: 18px;
}
</style>
